﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Playbook.Core.ViewModel
{
    /// <summary>
    /// Represents a comment.
    /// </summary>
    public sealed class CommentViewModel: ViewModelBase
    {
        private Guid _id;
        private string _body;
        private DateTime _createDate;
        private CommentTypes _type;
        private MemberViewModel _member;

        private SimpleCommand<object> _saveCommand;
        private SimpleCommand<object> _deleteCommand;

        public CommentViewModel()
            : base()
        {
            _saveCommand = new SimpleCommand<object>
            {
                CanExecuteDelegate = x => !string.IsNullOrWhiteSpace(this.Body), // Do we have a comment?
                ExecuteDelegate = x => Services.CommentServices.SaveComment(this) // Save the comment.
            };

            _deleteCommand = new SimpleCommand<object>
            {
                CanExecuteDelegate = x => !ID.Equals(Guid.Empty), // Do we have a comment identifier?
                ExecuteDelegate = x => Services.CommentServices.DeleteComment(this.ID) // Delete the comment.
            };
        }

        /// <summary>
        /// Identifier for the comment.
        /// </summary>
        public Guid ID { get { return _id; } set { _id = value; base.RaisePropertyChanged("ID"); } }

        /// <summary>
        /// Body of the comment.
        /// </summary>
        public string Body { get { return _body; } set { _body = value; base.RaisePropertyChanged("Body"); } }

        /// <summary>
        /// Date and time comment was made.
        /// </summary>
        public DateTime CreateDate { get { return _createDate; } set { _createDate = value; base.RaisePropertyChanged("CreateDate"); } }

        /// <summary>
        /// Type of comment this is.
        /// </summary>
        public CommentTypes Type { get { return _type; } set { _type = value; base.RaisePropertyChanged("Type"); } }

        /// <summary>
        /// Member who owns this comment.
        /// </summary>
        public MemberViewModel Member { get { return _member; } set { _member = value; base.RaisePropertyChanged("Member"); } }

        /// <summary>
        /// Saves the comment.
        /// </summary>
        public ICommand<object> Save { get { return _saveCommand; } }

        /// <summary>
        /// Deletes the comment.
        /// </summary>
        public ICommand<object> Delete { get { return _deleteCommand; } }
    }
}
